import Vue from 'vue'
import App from './App.vue'
import store from './vuex/store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import VueRouter from "vue-router"
import routers from './router/router'
import axios from 'axios'
//配置axios
Vue.prototype.$http = axios

Vue.prototype.$http.interceptors.request.use(
  config => {
    if (store.state.token) {
      config.headers.Authorization = `token ${store.state.token}`;
      console.log("main.js -> store.state.token --> " + store.state.token);
    }
    return config;
  },
  err => {
    return Promise.reject(err);
  });

//开启debug模式
Vue.config.debug = true;
Vue.use(ElementUI)
Vue.use(VueRouter);

import mock from './data/mock'
mock.analog()


// 创建一个路由器实例并且配置路由规则
const router = new VueRouter({
  mode: 'history',
  base: __dirname,
  routes: routers
})

// 路由器会创建一个 App 实例，并且挂载到选择符 #app 匹配的元素上。
const app = new Vue({
  router: router,
  store,
  render: h => h(App)
}).$mount('#app')

